<?php
/**
* ABSoft Banner Item
* @version 1.0
* @since Apr 2, 2011
* 
* Change logs
* Aug 23, 2011 - trungdt - Add desc property, to compatible with Thanhoc Online Project
*/
class abbanner {
	/**
	* Generate edit form
	* 
	* @param mixed $object
	* @param mixed $config
	* @param mixed $type Shown type, =0 for Text, =2 for Flash, =1 for Image
	* @return form
	*/
	function form($object, $config, $type) {
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();

		$form = new form();
		if (!isset($object->id)) {
			$object->show_type=$type;
			$object->rank=0;
			$object->title="";
			//
			$object->text_value="";
			//
			$object->img_fileid=-1;
			$object->img_linkurl="";
			//
			$object->flash_fileid=-1;
			$object->flash_linkurl="";
			//
			$object->desc="";
		} else {
			$form->meta('id',$object->id);
		}
		
		$form->register('title','Title',new textcontrol($object->title));
		$form->register('desc','Description',new textcontrol($object->desc));
		if ($object->show_type == 0) // text
		{
			$form->register('text_value','Text',new htmleditorcontrol($object->text_value));
		}
		else if ($object->show_type == 1) // image
		{
			$form->register('img_fileid','Image', new ajax_select_file("img_fileid",0,$object->img_fileid,true));
			$form->register('img_linkurl','Image URL',new textcontrol($object->img_linkurl));
		}
		else if ($object->show_type == 2) // flash
		{
			$form->register('flash_fileid','Flash', new ajax_select_file("flash_fileid",0,$object->flash_fileid,true));
			$form->register('flash_linkurl','Flash URL',new textcontrol($object->flash_linkurl));
		}
		
		$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
		return $form;
	}

	function update($values,$object) {
		$object->title = $values['title'];
		$object->desc = $values['desc'];
		$object->show_type = intval($values['type']);
		
		if ($object->show_type == 0) // text 
		{
			$object->text_value = $values['text_value'];
		}
		else if ($object->show_type == 1) // image
		{
			$object->img_fileid = $values['img_fileid'];
			$object->img_linkurl = $values['img_linkurl'];
		}
		else if ($object->show_type == 2) // flash
		{
			$object->flash_fileid = $values['flash_fileid'];
			$object->flash_linkurl = $values['flash_linkurl'];
		}
		return $object;
	}
}

?>